home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / asm4.zip / SIZE.ASM < prev    next >
Assembly Source File  |  1986-02-05  |  7KB  |  224 lines

  1.       title  SIZE.ASM by Art Merrill
  2.       page,132
  3. cseg      segment para 'code'
  4.       assume cs:cseg
  5. main      proc     far
  6.       org     100h
  7. start:      jmp     begin
  8.  
  9. banner    db     lf,'SIZE Vers 1.0 - ',cr,lf,'$'
  10.           db     'Copyright (C) 1985',cr,lf,'$'
  11.           db     'Ziff-Davis Publishing Company',cr,lf,'$'
  12. lf      equ     0ah
  13. cr      equ     0dh
  14. dta      equ     80h
  15. drive     db     0,':'
  16. root      db     '\'
  17. global    db     '*.*'
  18. buffer      db     65 dup(0)
  19. count      dw     0
  20. tot_bytes dw     0,0
  21. disk_bloks dw     0
  22. fix_bloks dw     0
  23.  
  24. asc_bytes db     lf,8 dup(0),' bytes in '
  25. asc_files db     4 dup(0),' file(s)',cr,lf
  26. asc_disk  db     8 dup(0),' bytes required on diskette(s)',cr,lf
  27. asc_fix   db     8 dup(0),' bytes required on fixed disk',cr,lf,lf,'$'
  28.  
  29. errmsg    db     lf,'Invalid parameter(s)',cr,lf
  30.           db     'or file(s) not found',cr,lf,lf,'$'
  31. begin:
  32.       push     ds               ;set up stack for return
  33.       sub     ax,ax
  34.       push     ax
  35.  
  36.       mov     dx,offset banner      ;print banner
  37.       mov     ah,9
  38.       int     21h
  39.  
  40. ;get current drive
  41.  
  42.       mov     di,offset drive       ;storage area for drive
  43.       mov     dx,offset global      ;we may need this address later
  44.       mov     ah,19h            ;current disk function
  45.       int     21h
  46.       add     al,41h            ;convert to ascii
  47.       stosb                ;store it
  48.  
  49. ;check for parameters
  50.  
  51.       cld                   ;clear direction flag
  52.       mov     di,offset buffer      ;set up register for storage
  53.       mov     si,dta            ;start of data transfer area (dta)
  54.       lodsb                ;get first byte
  55.       cmp     al,0               ;zero indicates no parms entered
  56.       jnz     aaa               ;parms were entered
  57.       call     add_global           ;add global chars
  58.       jmp     find_first           ;proceed with search
  59. aaa:
  60.           cmp    al,2                  ;did user enter just '\'?
  61.       jnz     aac               ;no
  62.       inc     si
  63.       lodsb
  64.           cmp    al,'\'                ;check for backslash
  65.       jz     aab               ;found
  66.       jmp     error               ;not found-error exit
  67. aab:
  68.       mov     si,offset drive       ;move drive,backslash and
  69.       mov     cx,6               ;   global chars into buffer
  70. rep      movsb
  71.       jmp     find_first           ;proceed with search
  72. aac:
  73.       cmp     al,3               ;did user enter just a drive?
  74.       jnz     aag               ;no
  75.       inc     si
  76.       lodsb
  77.       or     al,20h            ;make lower case if not already
  78.           cmp    al,'a'                ;is it A or greater?
  79.       jge     aad               ;yes
  80.       jmp     error               ;no-error exit
  81. aad:
  82.           cmp    al,'d'                ;is it D or less?
  83.       jle     aae               ;yes
  84.       jmp     error               ;no-error exit
  85. aae:
  86.       stosb                ;store drive letter
  87.       lodsb                ;get next byte
  88.           cmp    al,':'                ;is it a colon?
  89.       jz     aaf               ;yes
  90.       jmp     error               ;no-error exit
  91. aaf:
  92.       stosb                ;store it
  93.       call     add_global           ;add global chars to buffer
  94.       jmp     find_first           ;proceed with search
  95. aag:
  96.       cmp     al,4               ;did user enter drive and \
  97.       jnz     aah               ;no
  98.       inc     si               ;yes-get next byte
  99.       mov     cx,3               ;get all 3 chars
  100. rep      movsb
  101.       call     add_global           ;add global chars to drive and \
  102.       jmp     find_first           ;proceed with search
  103. aah:
  104.       inc     si               ;user must have entered a path
  105. aai:
  106.       lodsb                ;load first char
  107.       cmp     al,0dh            ;is it end of entry?
  108.       jz     find_first           ;yes-proceed with search
  109.       stosb                ;no-store char
  110.       jmp     aai               ;get another byte
  111. find_first:
  112.       mov     dx,offset buffer      ;start of pathname in memory
  113.       mov     cx,20h            ;attribute to search for
  114.       mov     ah,4eh            ;find first function
  115.       int     21h
  116.       jnc     found_first           ;file found-proceed to find next
  117.       jmp     error               ;no file found or invalid path
  118. found_first:
  119.       call     tally               ;add to running total
  120. find_next:
  121.       mov     ah,4fh            ;find next function
  122.       int     21h
  123.       jc     count_up           ;no more files found
  124.       call     tally               ;add to running total
  125.       jmp     find_next           ;look for another
  126. count_up:
  127.       mov     ax,tot_bytes           ;low word of total bytes
  128.       mov     dx,tot_bytes+2        ;high word of total bytes
  129.       mov     di,offset asc_bytes+8 ;end of output string
  130.       call     ascii               ;convert to ascii
  131.  
  132.       mov     ax,count           ;get total number of files
  133.       sub     dx,dx               ;clear high word
  134.       mov     di,offset asc_files+3 ;end of output string
  135.       call     ascii               ;convert to ascii
  136.  
  137.       mov     ax,disk_bloks           ;total blocks for diskette
  138.       mov     bx,400h           ;1024 decimal=2 clusters
  139.       mul     bx
  140.       mov     di,offset asc_disk+7  ;end of output string
  141.       call     ascii               ;convert to ascii
  142.  
  143.       mov     ax,fix_bloks           ;total blocks for fixed disk
  144.       mov     bx,1000h           ;4096 decimal=4 clusters
  145.       mul     bx
  146.       mov     di,offset asc_fix+7   ;end of output string
  147.       call     ascii               ;convert to ascii
  148.  
  149.       mov     dx,offset asc_bytes   ;start of printout
  150.       jmp     exit
  151. error:
  152.       mov     dx,offset errmsg
  153. exit:
  154.       mov     ah,9               ;DOS function - print string
  155.       int     21h
  156.  
  157.       ret
  158.  
  159. main      endp
  160.  
  161. add_global proc  near
  162.       xchg     si,dx               ;location of global chars
  163.       mov     cx,3               ;number of chars
  164. rep      movsb
  165.       ret
  166. add_global endp
  167.  
  168. ascii      proc     near
  169.       xchg     bp,dx               ;save high word
  170.       mov     bx,0ah            ;divisor
  171.       mov     cl,30h            ;conversion for ascii
  172. aaj:
  173.       xchg     ax,bp               ;get high word
  174.       sub     dx,dx               ;clear register
  175.       div     bx
  176.       xchg     bp,ax               ;this will be the new high word
  177.       div     bx               ;divide low word + remainder
  178.       or     dl,cl               ;convert new remainder to ascii
  179.       mov     [di],dl           ;quotient into storage
  180.       dec     di               ;step back one byte
  181.       cmp     ax,0               ;are we done?
  182.       jnz     aaj               ;no
  183.       ret                   ;yes-exit
  184. ascii      endp
  185.  
  186. tally      proc     near
  187.       sub     dx,dx               ;clear register
  188.       inc     count               ;add 1 more file to count
  189.       mov     bp,9ah            ;location of files size in psp
  190.       mov     ax,[bp]           ;get low word
  191.       mov     dx,[bp+2]           ;get high word
  192.       push     dx               ;save for next step
  193.       push     ax               ;save for next step
  194.       mov     bx,400h           ;1024 decimal=2 clusters
  195.       div     bx
  196.       cmp     dx,0               ;is there a remainder?
  197.       jz     aak               ;no
  198.       inc     disk_bloks           ;yes-add another block to running total
  199. aak:
  200.       add     disk_bloks,ax           ;add number of blocks to running total
  201.       pop     ax               ;get back low word
  202.       pop     dx               ;get back high word
  203.       push     dx               ;save for next step
  204.       push     ax               ;save for next step
  205.       mov     bx,1000h           ;4096 decimal=4 clusters
  206.       div     bx
  207.       cmp     dx,0               ;is there a remainder?
  208.       jz     aal               ;no
  209.       inc     fix_bloks           ;yes-add another block to running total
  210. aal:
  211.       add     fix_bloks,ax           ;add number of blocks to running total
  212.       pop     ax               ;get back low word
  213.       add     tot_bytes,ax           ;add low word to running total
  214.       jnc     no_carry
  215.       inc     tot_bytes+2           ;bump up high word
  216. no_carry:
  217.       pop     ax               ;get back high word
  218.       add     tot_bytes+2,ax        ;add high word to running total
  219.       ret                   ;exit
  220. tally      endp
  221.  
  222. cseg      ends
  223.       end     start
  224.